﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace InvoiceProject.Models
{
    public class BaseModel:IValidatableObject
    {
  

        public long Id { get; set; }

        //[Required]
        //[ReadOnly(true)]
        //public DateTime DateCreated { get; set; }

        [Display(Name = " ")]
        public DateTime DateModified { get; set; }

        //[Required]
        //[ReadOnly(true)]
        //public string UserCreated { get; set; }

       
   
        public string UserModified { get; set; }

        public void UpdateModelForSave(string userName)
        {
            if (Id == 0)
            {
                //DateCreated = DateTime.Now;
                //UserCreated = userName;
            }

            DateModified = DateTime.Now;
            UserModified = userName;
        }


        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
         
        //  // /// if (DateCreated == default(DateTime))
        //  // //     yield return new ValidationResult("DateCrated is not supplied");

            if (DateModified == default(DateTime))
                yield return new ValidationResult("DateModified is not supplied");

        //  ////  if (String.IsNullOrEmpty(UserCreated))
        //  ////      yield return new ValidationResult("UserCreated, is null");

            if (String.IsNullOrEmpty(UserModified))
                yield return new ValidationResult("UserModified, is null");


        }


    }

  
}